package com.lyb.common;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.Calendar;
import java.util.Map;

public class JWTUtils {
    private static final String SING = "XIAOSHUANG";
    public static String getToken(Map<String,String> map){
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.DATE,7);
        JWTCreator.Builder builder = JWT.create();
//        map.forEach((k,v)->{
//            builder.withClaim(k,v);
//        });
//        for(String key:map.keySet()){
//            builder.withClaim(key,map.get(key));
//        }
//        builder.withClaim("aaa",1);
        String token = builder.withClaim("aaa",1).withExpiresAt(instance.getTime()).sign(Algorithm.HMAC256(SING));
        return token;
    }
    public static DecodedJWT verify(String token){
        return JWT.require(Algorithm.HMAC256(SING)).build().verify(token);
    }
}
